﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class _Smallsizemachinetapswithhelicalflutes1
    {
        public static void Smallsizemachinetapswithhelicalflutes1(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double d = 4.76;
            double l = 11.14;
            double l1 = 12.84;
            double l4 = 1.94;
            double L = 41.37;
            double d4 = 5.89;
            double l2 = 6.62;
            double l5 = 2;

            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + L + 4, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 2, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + d / 2 - 0.5);
            Vector2 v5 = new Vector2(v3.X + 0.76, v3.Y + d / 2);
            Vector2 v6 = new Vector2(v3.X + l1, v5.Y);
            Vector2 v7 = new Vector2(v6.X + l2, v3.Y + d4 / 2);
            Vector2 v8 = new Vector2(v3.X + L - d4 / 4.656, v7.Y);
            Vector2 v9 = new Vector2(v8.X + d4 / 4.656, v8.Y - d4 / 4.656);
            Vector2 v10 = new Vector2(v9.X, v9.Y * -1);
            Vector2 v11 = new Vector2(v8.X, v8.Y * -1);
            Vector2 v12 = new Vector2(v7.X, v7.Y * -1);
            Vector2 v13 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v14 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v15 = new Vector2(v4.X, v4.Y * -1);
            Vector2 v16 = new Vector2(v9.X - l2, v8.Y);
            Vector2 v17 = new Vector2(v16.X, v9.Y - d4 / 4.656);
            Vector2 v18 = new Vector2(v8.X, v17.Y);
            Vector2 v19 = new Vector2(v18.X, v18.Y * -1);
            Vector2 v20 = new Vector2(v17.X, v19.Y);
            Vector2 v21 = new Vector2(v20.X, v11.Y);
            Vector2 v22 = new Vector2(v3.X, v3.Y - d / 5.231);
            Vector2 v23 = new Vector2(v3.X + l / 3.428, v14.Y);
            Vector2 v24 = new Vector2(v3.X, v3.Y + d / 7.212);
            Vector2 v25 = new Vector2(v3.X + l / 1.576, v14.Y);
            Vector2 v26 = new Vector2(v3.X + l, v25.Y);
            Vector2 v27 = new Vector2(v26.X, v26.Y + d / 14.875);
            Vector2 v28 = new Vector2(v5.X + l / 1.979, v5.Y);
            Vector2 v29 = new Vector2(v26.X, v26.Y + d / 1.676);
            Vector2 v30 = new Vector2(v27.X, v28.Y);
            Vector2 v31 = new Vector2(v29.X + (l1 - l) / 1.604, v29.Y - (v30.X - v28.X + (l1 - l) / 1.604) / ((v30.X - v28.X) / (v30.Y - v29.Y)) + (v30.Y - v29.Y));
            Vector2 v32 = new Vector2(v6.X, v31.Y - d / 4.621);
            Vector2 a1 = new Vector2(v13.X, v1.Y);

            Vector2 v33 = new Vector2(v2.X + 1, v2.Y);
            Vector2 v34 = new Vector2(v33.X + d4 + 4, v33.Y);
            Vector2 v35 = new Vector2(v33.X + d4 / 2 + 2, v33.Y + d4 / 2 + 2);
            Vector2 v36 = new Vector2(v35.X, v35.Y - d4 - 4);
            Vector2 v37 = new Vector2(v35.X, v8.Y + 0.2);
            Vector2 v39 = new Vector2(v37.X, v11.Y - 0.2);
            Vector2 v38 = new Vector2(v37.X - (v37.Y - v33.Y), v33.Y);
            Vector2 v40 = new Vector2(v37.X + (v37.Y - v33.Y), v33.Y);
            Vector2 v41 = new Vector2(v40.X - (v40.X - v37.X) / 2, v40.Y + (v40.X - v37.X) / 2);


            LwPolyline line1 = new LwPolyline();
            line1.Vertexes.Add(new LwPolylineVertex(v4));
            line1.Vertexes.Add(new LwPolylineVertex(v5));
            line1.Vertexes.Add(new LwPolylineVertex(v6));
            line1.Vertexes.Add(new LwPolylineVertex(v7));
            line1.Vertexes.Add(new LwPolylineVertex(v12));
            line1.Vertexes.Add(new LwPolylineVertex(v13));
            line1.Vertexes.Add(new LwPolylineVertex(v14));
            line1.Vertexes.Add(new LwPolylineVertex(v15));
            line1.Vertexes.Add(new LwPolylineVertex(v4));
            fun.PolyFill(dxf, line1, 0.1, contour);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v7));
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            line2.Vertexes.Add(new LwPolylineVertex(v16));
            line2.Vertexes.Add(new LwPolylineVertex(v17));
            line2.Vertexes.Add(new LwPolylineVertex(v18));
            line2.Vertexes.Add(new LwPolylineVertex(v19));
            line2.Vertexes.Add(new LwPolylineVertex(v20));
            line2.Vertexes.Add(new LwPolylineVertex(v21));
            line2.Vertexes.Add(new LwPolylineVertex(v11));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            fun.PolyFill(dxf, line2, 0.1, contour);

            Arc arc1 = fun.DrawArc3(v18, v9, v8);
            fun.drawBArc(dxf, arc1, 0.1, contour);

            Arc arc2 = fun.DrawArc3(v11, v10, v19);
            fun.drawBArc(dxf, arc2, 0.1, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v9));
            line3.Vertexes.Add(new LwPolylineVertex(v10));
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v22));
            line4.Vertexes.Add(new LwPolylineVertex(v23));
            line4.Vertexes.Add(new LwPolylineVertex(v25));
            line4.Vertexes.Add(new LwPolylineVertex(v24));
            fun.PolyFill(dxf, line4, 0.1, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v26));
            line5.Vertexes.Add(new LwPolylineVertex(v27));
            line5.Vertexes.Add(new LwPolylineVertex(v5));
            line5.Vertexes.Add(new LwPolylineVertex(v28));
            line5.Vertexes.Add(new LwPolylineVertex(v29));
            line5.Vertexes.Add(new LwPolylineVertex(v30));
            line5.Vertexes.Add(new LwPolylineVertex(v29));
            line5.Vertexes.Add(new LwPolylineVertex(v31));
            fun.PolyFill(dxf, line5, 0.1, contour);

            Arc arc3 = fun.DrawArc3(v27, v32, v31);
            fun.drawBArc(dxf, arc3, 0.1, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v6));
            line6.Vertexes.Add(new LwPolylineVertex(v13));
            fun.PolyFill(dxf, line6, 0.1, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v41));
            line7.Vertexes.Add(new LwPolylineVertex(v40));
            line7.Vertexes.Add(new LwPolylineVertex(v39));
            line7.Vertexes.Add(new LwPolylineVertex(v38));
            line7.Vertexes.Add(new LwPolylineVertex(v37));
            line7.Vertexes.Add(new LwPolylineVertex(v41));
            line7 = Pus.Fillet4LwPline(line7, 1, 0.8);
            line7 = Pus.Fillet4LwPline(line7, 3, 0.8);
            line7 = Pus.Fillet4LwPline(line7, 5, 0.8);
            line7 = Pus.Fillet4LwPline(line7, 7, 0.8);
            fun.PolyFill(dxf, line7, 0.1, contour);

            Line line8 = new Line(v1, v2);
            line8.Layer = centre;
            line8.Linetype = Linetype.DashDot;
            line8.LinetypeScale = 3;
            dxf.AddEntity(line8);

            Line line9 = new Line(v33, v34);
            line9.Layer = centre;
            line9.Linetype = Linetype.DashDot;
            line9.LinetypeScale = 3;
            dxf.AddEntity(line9);

            Line line10 = new Line(v35, v36);
            line10.Layer = centre;
            line10.Linetype = Linetype.DashDot;
            line10.LinetypeScale = 3;
            dxf.AddEntity(line10);





            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v5));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v24));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 89, 2.5, hline1, harc1, hatching);

            LwPolyline hatchpoly2 = new LwPolyline();
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v22));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v23));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v14));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v15));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v22));
            hatchpoly2.IsClosed = true;
            String[] htype2 = new String[100];
            Line[] hline2 = new Line[100];
            Arc[] harc2 = new Arc[100];
            int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多
                                                       //
                                                       //少
            for (int i = 0; i < hnumst2; i++)
            {
                htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype2[i] == "Line")
                {
                    hline2[i] = (Line)hatchpoly2.Explode()[i];
                }
                if (htype2[i] == "Arc")
                {
                    harc2[i] = (Arc)hatchpoly2.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype2, hnumst2, 89, 2.5, hline2, harc2, hatching);

            LwPolyline hatchpoly3 = new LwPolyline();
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v28));
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v29));
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v30));
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v28));
            hatchpoly3.IsClosed = true;
            String[] htype3 = new String[100];
            Line[] hline3 = new Line[100];
            Arc[] harc3 = new Arc[100];
            int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多
                                                       //
                                                       //少
            for (int i = 0; i < hnumst3; i++)
            {
                htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype3[i] == "Line")
                {
                    hline3[i] = (Line)hatchpoly3.Explode()[i];
                }
                if (htype3[i] == "Arc")
                {
                    harc3[i] = (Arc)hatchpoly3.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype3, hnumst3, 89, 2.5, hline3, harc3, hatching);

            LwPolyline hatchpoly4 = new LwPolyline();
            hatchpoly4.Vertexes.Add(new LwPolylineVertex(v41));
            hatchpoly4.Vertexes.Add(new LwPolylineVertex(v40));
            hatchpoly4.Vertexes.Add(new LwPolylineVertex(v39));
            hatchpoly4.Vertexes.Add(new LwPolylineVertex(v38));
            hatchpoly4.Vertexes.Add(new LwPolylineVertex(v37));
            hatchpoly4.Vertexes.Add(new LwPolylineVertex(v41));
            hatchpoly4 = Pus.Fillet4LwPline(line7, 1, 0.8);
            hatchpoly4 = Pus.Fillet4LwPline(line7, 3, 0.8);
            hatchpoly4 = Pus.Fillet4LwPline(line7, 5, 0.8);
            hatchpoly4 = Pus.Fillet4LwPline(line7, 7, 0.8);
            hatchpoly4.IsClosed = true;
            String[] htype4 = new String[100];
            Line[] hline4 = new Line[100];
            Arc[] harc4 = new Arc[100];
            int hnumst4 = hatchpoly4.Explode().Count;  //记录爆炸后，线段有多
                                                       //
                                                       //少
            for (int i = 0; i < hnumst4; i++)
            {
                htype4[i] = hatchpoly4.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype4[i] == "Line")
                {
                    hline4[i] = (Line)hatchpoly4.Explode()[i];
                }
                if (htype4[i] == "Arc")
                {
                    harc4[i] = (Arc)hatchpoly4.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype4, hnumst4, 45, 5, hline4, harc4, hatching);


            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;


            fun.dimrot1(dxf, v4, new Vector2 (v4.X +l5,v5.Y ), 0, d / 2.4, 1, height, arrowsize, exline, "l5", "", "");

            fun.dimrot1(dxf, v5, v14, 90, d, 1, height, arrowsize, exline, "d", "", "");

            fun.dimrot1(dxf, v16 ,v21, 90, d, 1, height, arrowsize, exline, "d4", "", "");

            fun.dimrot1(dxf, v15, v26, 180, d, 1, height, arrowsize, exline, "l", "", "");

            fun.dimrot1(dxf, v15, v13, 180, d * 2, 1, height, arrowsize, exline, "l1", "", "");

            fun.dimrot1(dxf, v10, v21, 180, d, 1, height, arrowsize, exline, "l2", "", "");

            fun.jdbz2(dxf, new Line(v27, fun.Polar(v27, -23 * pi / 180, 0.1)), new Line(a1, fun.Polar(a1, 0 * pi / 180, 0.1)), l, height, arrowsize, exline, "ω", "", "");


            fun.dimrot1(dxf, v40, v39, -135, d, 1, height, arrowsize, exline, "a", "", "");



           




            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

}
}




